﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Concat
{
    class StructType : ConcatType
    {
        public string[] slots;
        public StructType[] children;

        public StructType(string name, string[] slots, params StructType[] children)
            : base(name)
        {
            this.name = name;
            this.slots = slots;
            this.children = children;
        }
        public StructType(StructType parent, string name, string[] slots, params StructType[] children)
            : this(name, slots, children)
        {
            parent.addChild(this);
            List<string> slotList = new List<string>(this.slots);
            slotList.AddRange(parent.slots);
            this.slots = slotList.ToArray();
        }

        public void addChild(StructType child)
        {
            List<StructType> list = new List<StructType>(children);
            list.Add(child);
            children = list.ToArray();
        }

        public StructObject new_obj()
        {
            return new StructObject(this, slots);
        }

        public override bool coversNotEqual(ConcatType other)
        {
            if (!(other is StructType)) return false;
            return children.Contains((ConcatType)other)
                || children.exists(child => child.covers(other));
        }
    }
}
